﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Reflection;
using HtmlAgilityPack;

namespace CrawlerManager
{
    public class CrawlerHelper
    {
        internal static List<Assembly> GetAssemblies()
        {
            List<Assembly> assemblies = new List<Assembly>();
            assemblies.Add(Assembly.LoadFrom(@"D:\javadoc\MVC3\Apps\NewsCrawler\Chip\bin\Debug\Chip.dll"));
            return assemblies;
        }

        public static DateTime CopyDateTime(DateTime copy, DateTime copyTo, int[] copyWhat, bool zeroHour)
        {
            if (zeroHour)
            {
                copyTo = copyZeroHour(copyTo);
            }
            copyWhat.ToList().ForEach(c =>
            {
                copyTo = _copyDateTime(copy, copyTo, c);
            });
            return copyTo;
        }

        private static DateTime zeroTime = DateTime.Parse("00:00:00");
        private static DateTime copyZeroHour(DateTime copy)
        {
            return new DateTime(copy.Year, copy.Month, copy.Day, zeroTime.Hour, zeroTime.Minute, zeroTime.Second);
        }

        private static DateTime _copyDateTime(DateTime copy, DateTime copyTo, int c)
        {
            //Second
            if (c == 1) return new DateTime(copyTo.Year, copyTo.Month, copyTo.Day, copyTo.Hour, copyTo.Minute, copy.Second);
            //Minute
            else if (c == 2) return new DateTime(copyTo.Year, copyTo.Month, copyTo.Day, copyTo.Hour, copy.Minute, copyTo.Second);
            //Hour
            else if (c == 3) return new DateTime(copyTo.Year, copyTo.Month, copyTo.Day, copy.Hour, copyTo.Minute, copyTo.Second);
            else return DateTime.MinValue;
        }
    }
}
